package com.cl.edu.entity;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Transient;

import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * 科目
 * Subject entity. 
 * @author lihx
 */
@Entity
@Table(name = "subject")
public class Subject implements java.io.Serializable {

	// Fields

	private Long id;			//科目id		
	private String name;		//科目名
	private String position;	//显示位置 0表示在注册时选身份为教师时所教科目时显示  1表示简单显示 2表示全部显示
	private String type;		//预留类别，在菜单上显示时可能会用
	private String encodeName;

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "name", length = 50)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "position", length = 50)
	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	@Column(name = "type", length = 50)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	public void setEncodeName(String encodeName) {
		this.encodeName = encodeName;
	}
	@Transient
	public String getEncodeName() {
		try {
			if("舞蹈".equals(name)){
				return URLEncoder.encode("舞", "utf-8");	
			}else{
				return URLEncoder.encode(name, "utf-8");
			}
		} catch (UnsupportedEncodingException e) {
			return "";
		}
	}
}